package com.ifi.client.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnectionManager {
	private static Connection instance = null;
	private static String dbFile = "jeuxauxcartes";

	public DBConnectionManager(){
		
	}
	
	public static Connection getConnection(){
		if(instance==null){
			try {
				Class.forName("org.sqlite.JDBC");
				instance = DriverManager.getConnection("jdbc:sqlite:" + dbFile);
			} catch (ClassNotFoundException classNotFound) {
				classNotFound.printStackTrace();
			} catch (SQLException e) {

			}
		}
		return instance;
	}
	
	public static boolean closeConnection(){
		if(instance!=null){
			try {
				instance.close();
				return true;
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return false;
	}
}
